package com.example.nacosdemo1.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/nacosDemo")
@RefreshScope
public class NacosDemoController {


    @Value("${pattern.datefromat}")
    private String dateFormat;

    @GetMapping("/hello/{name}")
    public JSONObject hello(@PathVariable("name") String name){
        JSONObject json =  new JSONObject();
        json.put("name", name);
        System.out.println(json);
        return json ;
    }


    @GetMapping("/now")
    public String now(){

        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateFormat));
    }
}
